
#include "vec.h"

using namespace Blox;

Vec const Vec::Right(1.0f,0.0f,0.0f);
Vec const Vec::Up(0.0f,1.0f,0.0f);
Vec const Vec::Forward(0.0f,0.0f,1.0f);
Vec const Vec::AllZero(0.0f,0.0f,0.0f);
Vec const Vec::AllOne(1.0f,1.0f,1.0f);

Bounds::Bounds( AABB const & rBox )
	: vMin(rBox.vCentre-rBox.vExtents)
	, vMax(rBox.vCentre+rBox.vExtents)
{}

void Bounds::Set( AABB const & rBox )
{
	vMin = (rBox.vCentre-rBox.vExtents);
	vMax = (rBox.vCentre+rBox.vExtents);
}


AABB::AABB( Bounds const & rBounds )
	: vCentre((rBounds.vMax+rBounds.vMin)*0.5f)
	, vExtents((rBounds.vMax-rBounds.vMin)*0.5f)
{}

void AABB::Set( Bounds const & rBounds )
{
	vCentre = ((rBounds.vMax+rBounds.vMin)*0.5f);
	vExtents = ((rBounds.vMax-rBounds.vMin)*0.5f);
}

void Blox::AABB::GetCornerExtents( Vec * pCorners, float fScale /*= 1.0f*/ ) const
{
	static Vec const aCorner[8] =
	{
		Vec( -1.0f, -1.0f, -1.0f ),
		Vec( -1.0f, -1.0f,  1.0f ),
		Vec( -1.0f,  1.0f, -1.0f ),
		Vec( -1.0f,  1.0f,  1.0f ),
		Vec(  1.0f, -1.0f, -1.0f ),
		Vec(  1.0f, -1.0f,  1.0f ),
		Vec(  1.0f,  1.0f, -1.0f ),
		Vec(  1.0f,  1.0f,  1.0f )
	};
	Vec const vScaledExtents( vExtents * fScale );
	for( u32 u=0; u<8; u++ )
	{
		Vec::Mul( pCorners[u], vScaledExtents, aCorner[u] );
	}
}
